package com.zzyl.controller.app;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationPageDto;
import com.zzyl.entity.MemberElder;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//客户预约管理
@RestController
public class AppReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    //查询当前用户当天的取消预约次数
    @GetMapping("/customer/reservation/cancelled-count")
    public ResponseResult getCancelledCount() {
        Integer count = reservationService.getCancelledCount();
        return success(count);
    }

    @GetMapping("/customer/reservation/countByTime")
    public ResponseResult getRemainingCount(Long time) {
        List<TimeCountVo> list = reservationService.getRemainingCount(time);
        return success(list);
    }
    @PostMapping("/customer/reservation")
    public ResponseResult save(@RequestBody Reservation reservation) {
        reservationService.saveReservation(reservation);
        return success();
    }

    //分页查询预约
    @GetMapping("/customer/reservation/page")
    public ResponseResult findByPage(ReservationPageDto dto) {
        PageResponse<Reservation> page = reservationService.findByPage(dto);
        return success(page);
    }

    //取消预约
    @PutMapping("/customer/reservation/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id) {
        Reservation reservation = new Reservation();
        reservation.setId(id);
        reservation.setStatus(2);
        reservationService.updateById(reservation);
        return success();
    }

}